package m1;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //连接
         ConnectionFactory f = new ConnectionFactory();
         f.setHost("192.168.111.140");  //wht6.cn
         f.setPort(5672);
         f.setUsername("admin");
         f.setPassword("admin");
         Connection con = f.newConnection();     //连接
         Channel c =con.createChannel();         //通信的通道
        //创建 helloworld 队列
        //如果服务器端，队列已经存在，不会重复的创建
        c.queueDeclare("helloworld-zxy",false,false,false,null);

        //向 helloworld 队列发送消息
        c.basicPublish("","helloworld-zxy",null,"Hello-world!".getBytes());
        System.out.println("消息已发送");
    }
}
